<?php

namespace app\admin\controller\yunfood\fund;

use addons\yunfood\model\FundRecord;
use addons\yunfood\library\Backend;

/**
 * 礼币 - 记录
 */
class Record extends Backend
{
    /**
     * @var FundRecord
     */
    protected $model;

    // 联表查询，解决字段冲突
    protected $relationSearch = true;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new FundRecord();

        // 行为
        $this->view->assign('actionList', $this->model::getActionList());
        $this->assignconfig('actionList', $this->model::getActionList());
    }

    /**
     * 查看
     */
    public function index()
    {
        $userId = $this->request->request('user_id');

        if ($this->request->isAjax()) {
            // 通用查询条件
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $query = $this->model->where($where);
            if ($userId) {
                $query->where(['user_id' => $userId]);
            }
            $list = $query->order($sort, $order)->limit($offset, $limit)->paginate($limit);

            $result = array(
                'total' => $list->total(),
                'rows'  => $list->items(),
            );

            return json($result);
        }

        return $this->view->fetch();
    }

    public function add()
    {
        return;
    }

    public function edit($ids = null)
    {
        return;
    }

    public function multi($ids = null)
    {
        return;
    }

    public function recyclebin()
    {
        return;
    }

    public function destroy($ids = null)
    {
        return;
    }

    public function restore($ids = null)
    {
        return;
    }
}
